home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RlShlEv.cpp
-
- Contains: Apple Event handlers for the document shell.
-
- Owned by: Eric House
-
- Copyright: © 1994 - 1997 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <11> 1/8/97 DH 1401434: Deal with deactivating and
- reactivating OD windows when dialogs are
- shown; make sure size is correct in dialog
- to change doc size;
- <10> 12/17/96 CSL 1611512: Don't call UpdateMenus from
- HandleHighLevelEvent.
- <9> 10/23/96 DH Fixed build break from previous checkin.
- <8> 10/23/96 DH Removed heap validation code from previous
- checkin.
- <7> 10/22/96 DH 1336808,1333949,1368888,1375780 Added new
- event to change the size of a document,
- including code to displays controls to do
- so.
- <6> 20.09.1996 NP 386083: Add include
- <5> 7/11/96 TJ Quit event does not return an error
- <4> 6/20/96 JP 1339269: Made quit handle the saving
- parameter too
- <3> 5/31/96 jpa T10012: Fixed 'oapp', 'odoc', 'pdoc'
- handlers for app-style (CyberDog) process
- model.
- <2> 5/8/96 NP 1304875: Infinite Save Changes dialog boxes
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _SIHELPER_
- #include <SIHelper.h>
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_ShellSI_xh
- #include "ShellSI.xh"
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef _SEUTILS_
- #include <SEUtils.h>
- #endif
-
- #ifndef _SHPRPACC_
- #include "ShPrpAcc.h"
- #endif
-
- #ifndef _SHLEVTHD_
- #include "ShlEvtHd.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include <NamRslvr.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include <ODOSLTkn.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef _SHELLDEF_
- #include <ShellDef.h>
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __AEUserTermTypes__
- #include <AEUserTermTypes.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _DOCUTILP_
- #include "DocUtilP.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __PALETTES__
- #include <Palettes.h>
- #endif
-
- #ifndef _MEMDEBG_
- #include "MemDebg.h"
- #endif
-
- #ifndef _SHELLDEF_
- #include "ShellDef.h"
- #endif
-
- #ifndef _WINUTILM_
- #include "WinUtilM.h"
- #endif
-
- #pragma segment ShellEvt
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define STATICBUILD
-
- const DescType kShellPropAccessor = 0x73706163; // 'spac';
- const DescType kShellSelfPropAccessor = 0x7368656C; // 'shel';
-
- const DescType kShellEventHandler = 'shev';
-
- const ODSize kDocSizeHighAlert = 128;
- const ODSize kFatalLowAppAlert = 131;
- const ODSize kLowAppMemAlert = 132;
-
- const short kNormalIconID = 128;
- const short kUpArrowIconID = 129;
- const short kDownArrowIconID = 130;
-
- const short kDecreaseMemBtn = 2;
-
- enum {
- kOKButton = 1,
- kCancelButton, // 2
- kArrowBottom, // 3
- kArrowTop, // 4
- kArrowControl, // 5
- kNewDocHeapPrefSizeFld, // 6
- kCurDocHeapPrefSizeFld, // 7
- kCurrentKText, // 8 new "K"
- kNewKText, // 9 current "K"
- kSaveChangesTxtItem=13 // 13 ; Save changes text item.
- };
-
- const unsigned long kSizeIncrement = (32 * 1024);
- const unsigned long kMaximumSize = (1024 * 1024 * 64);
- const short kControlInactive = 255;
- const short kControlActive = 0;
- const short kDefaultDocSizeRes = -1;
- //==============================================================================
- // Globals
- //==============================================================================
-
- extern ODULong gSize = 0;
- ODULong gOrigDocSize = 0;
-
- pascal void MyUserItemProc (DialogPtr dlog, short item);
- UserItemUPP gUserItemUPP = NewUserItemProc (MyUserItemProc);
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- //void CreateUniqueTmpFolderForFile(ODFileSpec* result, Str63 fileName);
-
- #define HANDLER_PARAMS \
- ODPart* thePart, \
- ODAppleEvent* message, \
- ODAppleEvent* reply, \
- ODSLong handlerRefcon
-
- // pascal ODError HandleClone(HANDLER_PARAMS);
- pascal ODError HandleClose(HANDLER_PARAMS);
- // pascal ODError HandleCountEl(HANDLER_PARAMS);
- // pascal ODError HandleMake(HANDLER_PARAMS);
- // pascal ODError HandleDelete(HANDLER_PARAMS);
- // pascal ODError HandleDoExist(HANDLER_PARAMS);
- // pascal ODError HandleGetClsInfo(HANDLER_PARAMS);
- // pascal ODError HandleGetData(HANDLER_PARAMS);
- // pascal ODError HandleGetDataSz(HANDLER_PARAMS);
- // pascal ODError HandleGetEvnInfo(HANDLER_PARAMS);
- // pascal ODError HandleMove(HANDLER_PARAMS);
- // pascal ODError HandleOpen(HANDLER_PARAMS);
- // pascal ODError HandlePrint(HANDLER_PARAMS);
- pascal ODError HandleSave(HANDLER_PARAMS);
- // pascal ODError HandleSetData(HANDLER_PARAMS);
- pascal ODError HandleODActivate(HANDLER_PARAMS);
-
- pascal ODError HandleGetAETE(HANDLER_PARAMS);
-
- #undef HANDLER_PARAMS
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon);
-
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* theAppleEvent,
- RealShell* self);
- void GetDirectParam(RealShell* self, AppleEvent* theAppleEvent,
- AEDesc* evtDp);
-
- static ODBoolean AskUserIncreaseDocSize(FSSpec* theFSSpec);
- static void DoDialogSetup( DialogPtr dialog, PlatformFile* docFile);
- static Boolean DoDialogHits(DialogPtr dialog, short itemHit, ODBoolean increaseSize,
- ODBoolean fatalLowMem);
- static void SetDialogMemorySize (DialogPtr dlog, Size size);
- pascal void MyUserItemProc (DialogPtr dlog, short item);
- static void DoMemorySettingHits(DialogPtr dialog, short itemHit, ODBoolean increaseSize,
- ODBoolean fatalLowMem);
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes);
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file);
- static ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID);
- static void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes);
- static void AttachUserItemProc (DialogPtr dlog, short item, UserItemUPP proc);
- static void PlotArrowIcon(DialogPtr dlog, short item);
- static void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue);
- static OSErr ReplaceTempSizeWithSize( short id );
- static void ODOutlineDefaultButtonDrawProc(DialogPtr theDialog, short theItem);
-
- //==============================================================================
- // RealShell
- //==============================================================================
-
- //-------------------------------------------------------------------------------------
- // Apple Event Initialization
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::InitAE()
- {
- Environment* ev = fEV;
-
- ShellSI* shellSemtInterface = new ShellSI;
- THROW_IF_NULL(shellSemtInterface);
- fSIHelper = new SIHelper;
- fSIHelper->InitSIHelper(fSession, shellSemtInterface);
- shellSemtInterface->InitCPlusSemanticInterface(ev, kODAppShell, fSIHelper,
- fSession);
- fSession->SetShellSemtInterface(ev, shellSemtInterface);
- shellSemtInterface->Release(ev); // SetShellSemtInterface acquires.
-
- ODObjectAccessorUPP newAccessor =
- NewODObjectAccessorProc( GetFileFromNULL );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallObjectAccessor( cFile,
- typeNull, newAccessor, (ODSLong)fSession );
-
- ODEventHandlerUPP newHandler =
- NewODEventHandlerProc( RealShell::HandleOpenAppEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenDocuments,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEPrintDocuments,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleQuitEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEQuitApplication,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleLaunchFailedEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kCFMLaunchFailedEventClass,
- kCFMLaunchFailedEventID,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleODActivate );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kAEOpenDocSuite,
- kODActivateEvent,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleDocSizeChangeInteraction );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- 'dumb',
- 'hack',
- newHandler ,
- (long)this);
-
- ODCoercionHandlerUPP fsSpecCoerceHdlr =
- NewODDescCoercionHandlerProc( RealShell::CoerceToFSSpec );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler( typeAlias, typeFSS,
- fsSpecCoerceHdlr, (long)this, kODTrue );
-
- // this->InstallObjectAccessors(shellSemtInterface);
-
- /*
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler(typeChar, typeFSS,
- (XMPCoercionHandler)Pathname2FSSpec, kNoRefCon,
- kFromTypeIsNotDesc );
- */
-
- ODEventHandlerUPP eventHandlerUPP;
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleClone);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClone,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleClose);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClose,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleCountEl);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECountElements,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMake);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECreateElement,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDelete);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDelete,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDoExist);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetClsInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetClassInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetData,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetDataSz);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetDataSize,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetEvnInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetEventInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMove);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEMove,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleOpen);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEOpen,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandlePrint);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEPrint,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleSave);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESave,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleSetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESetData,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- //#ifndef STATICBUILD
- // Just let AS get the resource directly if not ASLM. In fact, we
- // probably don't need this even in that case.
- eventHandlerUPP = NewODEventHandlerProc(HandleGetAETE);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAEOpenDocSuite, kGetAETE,
- eventHandlerUPP,
- (ODSLong)this);
- //#endif /* STATICBUILD */
-
- }
-
-
- void RealShell::HandleHighLevelEvent(ODEventData* event)
- {
- Environment* ev = fEV;
-
- if ( ((AEEventClass) event->message == 'aevt') && (*(AEEventID *) &(event->where) == 'odoc') )
- {
- // If the open document event was sent by the edition manager, the modifiers field
- // of the event will be garbage. This can cause AEProcessAppleEvent to return an error
- // instead of calling one of our event handlers.
- // We work around this by clearing the modifiers field. Note that clearing the field
- // is not correct if the event is larger than 64K; we take the chance that an 'odoc'
- // event won't be this large. [cc 7/19/95] [Radar #1261856]
- event->modifiers = 0;
- }
-
- ODBoolean succeeded = fSession->GetMessageInterface(ev)->ProcessSemanticEvent(ev, event);
- }
-
-
- //-------------------------------------------------------------------------------------
- // Handling 'oapp' Events
- //-------------------------------------------------------------------------------------
-
-
- pascal ODError RealShell::HandleOpenAppEvent(ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- /* Called when a stub application is starting up the OpenDoc shell
- at launch time -- e.g. CyberDog. */
-
- ODUnused(part);
- ODUnused(message);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODError error = noErr;
-
- TRY
-
- // Determine location (FSSpec) of current app:
- ProcessInfoRec info;
- FSSpec appLoc;
- self->GetCurrentProcessInfo(&info,NULL,&appLoc);
-
- TempPlatformFile file = new PlatformFile;
- file->Specify(&appLoc);
- self->OpenFile(file,kODTrue); // Force it to open APPL
-
- CATCH_ALL
- error = ErrorCode();
- self->GetSession()->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
-
- return error;
- }
-
-
- //-------------------------------------------------------------------------------------
- // Handling 'odoc' and 'pdoc' Events
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::FakePrintMenuEvent()
- {
- Environment* ev = fEV;
- ODDispatcher* dispatcher = this->GetSession()->GetDispatcher(ev);
-
- ODMenuID menu;
- ODMenuItemID menuItem;
- TempODMenuBar baseMenuBar = this->fWindowState->AcquireBaseMenuBar(ev);
- baseMenuBar->GetMenuAndItem(ev, kODCommandPrint, &menu, &menuItem );
-
- ODEventData event;
- event.message = (menu<<16) | menuItem;
- event.what = kODEvtMenu;
- // zero the rest of the fields
- WASSERT( sizeof(Point) == sizeof(long) ); // this is gross but
- *(long*)&event.where = 0L;
- event.when = 0L;
- event.modifiers = 0;
- dispatcher->Dispatch(ev, &event);
- }
-
-
- pascal ODError RealShell::HandleOpenPrintDocsEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- ODVolatile(session);
-
- long itemsInList;
- ODError error = noErr;
- AppleEvent realMessage;
- DescType eventID;
- DescType ignoreType;
- Size ignoreActual;
-
- TRY
-
- // get list of documents
- realMessage.dataHandle = kODNULL;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- TempAEDescStruct docList;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyDirectObject, typeAEList,
- &docList));
- THROW_IF_ERROR( AEGetAttributePtr( &realMessage, keyEventIDAttr, typeType,
- &ignoreType, &eventID, sizeof(eventID), &ignoreActual ));
- ODBoolean isPrint = eventID == kAEPrintDocuments;
- if (MissingParams(&realMessage))
- THROW( errAEParamMissed );
-
- // Iterate through all documents and open them:
- THROW_IF_ERROR( AECountItems(&docList, &itemsInList ));
- for (ODSLong index = 1; index <= itemsInList; index++) {
-
- ODFileSpec fileSpec;
- AEKeyword key,type;
- Size size;
- OSErr err = AEGetNthPtr(&docList, index, typeFSS, &key,&type,
- &fileSpec,sizeof(fileSpec),&size);
- if (err == errAECoercionFail)
- {
- // We'll handle tokens here...
- TempAEDescStruct coerceDesc, fileDesc;
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
-
- GetDirectParam(self, &realMessage, &coerceDesc);
- THROW_IF_ERROR( AEDescToODDesc(&coerceDesc, tmpWrapper ) );
- ODDesc* myToken;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- myToken = resolver->GetUserToken(ev, tmpWrapper);
- AEDisposeDesc( &coerceDesc );
- THROW_IF_ERROR( ODDescToAEDesc(myToken, &coerceDesc) );
- THROW_IF_ERROR( AECoerceDesc(&coerceDesc, typeFSS, &fileDesc) );
- ODBlockMove(*fileDesc.dataHandle,&fileSpec,sizeof(fileSpec));
- err = noErr;
- }
-
- // If printing, open each document in this process, then print and close it.
- // If this is an application process (CyberDog), open all documents in this process.
- // If this is a normal document process, open the first document in this process
- // if no document is open, and open the rest in separate processes.
- if( !err ) {
- TempPlatformFile file = new PlatformFile();
- file->Specify(&fileSpec);
- if( isPrint ) {
- ODDocument *doc = self->OpenFile(file);
- if( doc ) {
- self->FakePrintMenuEvent();
- if (ODCloseDocument(ev, session, doc))
- session->GetDispatcher(ev)->Exit(ev);
- }
- } else if( self->fAPPLProcess || (index==1 && ODGetFirstOpenDocument(ev, session)==kODNULL) )
- self->OpenFile(file);
- else
- self->OpenAnotherFile(file);
- }
- }
-
- CATCH_ALL
- error = ErrorCode();
- session->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
- ODDisposeAppleEvent( &realMessage );
-
- return error;
- } // HandleOpenPrintDocsEvent()
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleQuitEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleQuitEvent( ODPart* /*part*/,
- ODAppleEvent* message,
- ODAppleEvent* /*reply*/,
- long refCon)
- {
- ODError error = noErr;
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- ODDescType yesNoAsk = kAEAsk;
- ODDescType theType;
- ODSLong theSize;
- AEDesc event;
-
- TRY
- ODDescToAEDesc(message, &event);
- error = AEGetParamPtr(&event, keyAESaveOptions, typeEnumerated, &theType, &yesNoAsk, sizeof(yesNoAsk), &theSize);
- // we don't throw because we're quitting and don't care if there's an error
- error = noErr; // to keep it from being returned
-
- // In OpenDoc the 'QUIT' event means CloseDocument.
-
- RealShell* self = (RealShell*)refCon;
- ODDocument* document = kODNULL;
- while ((document = ODGetFirstOpenDocument(ev, session)) != kODNULL)
- {
- if (!self->CloseDocument(document, yesNoAsk))
- THROW(userCanceledErr);
- }
- session->GetDispatcher(ev)->Exit(ev);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleQuitEvent()
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleLaunchFailedEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleLaunchFailedEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- long launchErr;
- ProcessSerialNumber psn;
- Str255 appName, libName;
- AppleEvent realMessage;
-
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
-
- //<eeh> any chance this can throw???
- GetLaunchFailedParams(&realMessage, launchErr,&psn,appName,libName);
- ODDisposeAppleEvent(&realMessage);
-
- RealShell *shell = (RealShell*)refCon;
- shell->LaunchFailed(launchErr,psn,appName,libName);
- return noErr;
- }
-
-
- void
- RealShell::LaunchFailed( ODSLong launchErr, const ProcessSerialNumber &psn,
- Str255 appName, Str255 libName )
- {
- if( psn.lowLongOfPSN != kNoProcess ) {
- Boolean result;
- if( SameProcess(&psn,&fLastNewDocPSN,&result) == noErr && result != kODFalse ) {
- // This is a new document we just created & launched; better delete it.
- OSErr err= FSpDelete(&fLastNewDocSpec);
- if( err )
- WARN("Error %d trying to delete new document",err);
- fLastNewDocPSN.lowLongOfPSN = kNoProcess;
- fLastNewDocSpec.name[0] = '\0';
- }
- }
-
- this->ExceptionAlert(launchErr,kODNULL);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // • HandleDocSizeChangeInteraction
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleDocSizeChangeInteraction( ODPart* thePart,
- ODAppleEvent* message, ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- // if we get this event, we're being relaunched with what's known to
- // be less memory than the document wants ONLY FOR THE PURPOSE OF GIVING
- // the user a chance to lower the amount wanted. So put up a dialog here,
- // set a flag so the shell will quit asap after we return, and then send
- // an event to the system process (which should be the source of this
- // event) telling it whether the user wants to change the amount of memory
- // allocated (and relauch) or simply cancel the whole thing.
-
- // $$$$$ eeh - needs minimal error handling (there's really nothing to be
- // done but fail.)
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = self->fEV;
-
- AppleEvent realMessage;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- FSSpec docSpec;
- long ignore1;
- unsigned long ignore2;
-
- OSErr err = noErr;
-
- err = AEGetParamPtr( &realMessage, 'docs', typeFSS,
- &ignore2, (Ptr)&docSpec, sizeof(docSpec), &ignore1);
-
- ODBoolean changeMade = self->ChangeDocSize(&docSpec, kODFalse, kODFalse);
- // Lower size.
- ODError changeError = noErr;
-
- if ( changeMade == kODTrue )
- changeError = self->CloseAndReopenDoc(&docSpec);
- else
- // No further changes needed, so make this process go away.
- self->GetSession()->GetDispatcher(ev)->Exit(ev);
-
- return changeError;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // • CloseAndReopenDoc
- //
- // Method to close and reopen a document in one atomic action. Sends an Apple
- // event to the System process that will cause the current document to be closed
- // and reopened.
- //
- ////////////////////////////////////////////////////////////////////////////////
- ODError RealShell::CloseAndReopenDoc(FSSpec* docFSSpec)
- {
- AppleEvent newEvent;
- AEAddressDesc targetAddress;
- ODBoolean sysProcFound = kODFalse;
-
- ////////////////
- // Code to get psn of sys proc
- ////////////////
- ProcessSerialNumber iteratorPSN;
- ProcessInfoRec procInfo;
- FSSpec procSpec;
- OSErr error = noErr;
- OSErr err = noErr;
- OSErr err1 = noErr;
-
- // Needed to get first process from Process Mgr.
- iteratorPSN.highLongOfPSN = 0;
- iteratorPSN.lowLongOfPSN = kNoProcess;
-
- procInfo.processInfoLength = sizeof(procInfo);
- procInfo.processName = NULL;
- procInfo.processAppSpec = &procSpec;
-
- while (error != procNotFound)
- {
- error = GetNextProcess(&iteratorPSN);
- if (!error)
- error = GetProcessInformation(&iteratorPSN, &procInfo);
- if (!error)
- {
- if (procInfo.processSignature == kODShellSignature &&
- procInfo.processType == 'APPL')
- {
- sysProcFound = kODTrue;
- break;
- }
- }
- }
-
- if( sysProcFound == kODTrue )
- {
- ////////////////
- // Create and send CloseReopen event to system proc.
- ////////////////
- err = AECreateDesc(typeProcessSerialNumber, (Ptr)&iteratorPSN, sizeof(iteratorPSN),
- &targetAddress);
-
- err = AECreateAppleEvent( kODShellSignature, kODReopenDocEventID,
- &targetAddress, kAutoGenerateReturnID, kAnyTransactionID,
- &newEvent );
-
- if( err == noErr )
- {
- err1 = AEPutParamPtr( &newEvent, keyDirectObject, typeFSS, docFSSpec,
- sizeof(FSSpec) );
-
- ProcessSerialNumber psn;
- (void)GetCurrentProcess( &psn );
- err1 = AEPutParamPtr( &newEvent, 'duhh', typeProcessSerialNumber, &psn,
- sizeof(psn) );
-
- if( err == noErr && err1 == noErr )
- err = AESend( &newEvent, NULL, kAENoReply, kAEHighPriority,
- kAEDefaultTimeout, NULL, NULL );
- }
- }
- else
- return kODErrNotImplemented;
-
- return err;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // • ChangeDocSize
- //
- // Presents the user with controls to change the size of document process heap.
- // If the input parameter increaseSize is true, then the user will be unable to
- // decrease the size of the from its current size. If it is false, then the
- // user can only lower the size.
- //
- // dh - Note, this method was created to be used to control changing the size of
- // a document under low memory conditions. It does not support setting the document
- // to anything other than higher or lower than its current value. To do that, use
- // the Document Info controls.
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- ODBoolean RealShell::ChangeDocSize(FSSpec* theFSSpec, ODBoolean increaseSize, ODBoolean fatalLowMem)
- {
- short itemHit = kCancelButton;
- Handle itemHandle = kODNULL;
- short itemType;
- Boolean keepRuning = false;
- Rect scratchRect;
- ODBoolean userChangedSize = kODFalse;
- StringHandle tempString = kODNULL;
- short item = 0;
- OSErr err = noErr;
-
- CUsingLibraryResources duh;
-
- // Put the real SIZE resources back.
-
- short theCurResFile = CurResFile();
- short docResFile = FSpOpenResFile(theFSSpec,fsRdWrPerm);
-
- if (docResFile != -1)
- {
- err = ReplaceResourceWithNewType( kODTempSizeRsrcType, kSIZERsrcType, 0 );
- err = ReplaceResourceWithNewType( kODTempSizeRsrcType, kSIZERsrcType, 1 );
- CloseResFile( docResFile );
- UseResFile(theCurResFile);
- }
- PlatformFile* docFile = new PlatformFile();
- docFile->Specify((ODFileSpec*)theFSSpec);
-
- // dh - Deactivate all front windows. Could be multiple front windows because of floating windows.
- // If this is not a fatal low-memory situation, we can use OpenDoc API to do this. Otherwise,
- // serious hacks ensue. These hacks cause problems with the process menu and the About This Mac
- // window, but since the process is going away, it shouldn't be noticable to the user.
-
- CStackPtrList winList;
- WindowListIterator theWinIter;
- WindowPtr theWin = theWinIter.First();
-
- if( theWin != NULL )
- {
- do
- {
- if( GetWindowHilite(theWin) )
- {
- HiliteWindow( theWin, false );
- winList.Add( theWin );
- }
- theWin = theWinIter.Next();
- } while( theWin != NULL );
- }
-
- InitCursor();
- // If we are decreasing the size, this means that we are servicing an event from the
- // system process that responds to a document that has a size that is too high to
- // open.
- if( increaseSize == kODFalse )
- {
- // First check to see if the doc is read-only. If so, cannot change size, so
- // inform the user of other options to open document.
- PlatformFile thefile;
- thefile.Specify( theFSSpec );
- if( thefile.IsLocked() )
- item = CautionAlert( kSHLphDocSizeChangeRO, kODNULL );
- else
- item = CautionAlert( kSHLphDocSizeChange, kODNULL );
- }
- // Otherwise, free app heap space has gotten too low and the user wants to increase
- // the size of the document.
- else
- {
- if( fatalLowMem )
- item = CautionAlert( kSHLphAppSpaceIsLowFatal, kODNULL);
- else
- item = CautionAlert( kSHLphAppSpaceIsLow, kODNULL );
- }
- if( ( increaseSize == kODFalse && item == kDecreaseMemBtn ) || ( increaseSize == kODTrue && item == kOKButton ) )
- {
- DialogPtr dialog = GetNewDialog (kSHLphAppSpaceIsLowDlg, nil, (WindowPtr) -1);
- if (dialog)
- {
-
- ODULong curPreferredSize = DHGetDocumentPreferredHeapSize(docFile);
- if( curPreferredSize == 0 )
- curPreferredSize = DHGetPreferredSizeInSIZE(docFile, kDefaultDocSizeRes);
- gSize = curPreferredSize*1024;
- gOrigDocSize = gSize;
-
- DoDialogSetup(dialog, docFile);
- if( increaseSize == kODTrue )
- tempString = GetString(kSHLIncreaseSizeSTR);
- else
- tempString = GetString(kSHLDecreaseSizeSTR);
- HLock( (Handle)tempString );
- ParamText(*tempString, kODNULL, kODNULL, kODNULL);
- DisposeHandle( (Handle)tempString );
-
- do
- {
- ModalDialog(NULL, &itemHit);
- GetDialogItem(dialog, itemHit, &itemType, &itemHandle, &scratchRect);
- keepRuning = DoDialogHits(dialog, itemHit,increaseSize,fatalLowMem);
- } while ((itemHit != kOKButton) && (itemHit != kCancelButton));
-
- if( itemHit == kOKButton )
- {
- if (gSize != curPreferredSize )
- {
- DHSetDocumentPreferredHeapSize(docFile, gSize/1024);
- userChangedSize = kODTrue;
- }
- }
-
- DisposeDialog(dialog);
- delete docFile;
- }
- }
-
- // Now activate the windows again.
- int count = winList.GetNumListItems();
-
- if( count > 0 )
- {
- theWin = (WindowPtr)winList.First();
- do
- {
- HiliteWindow( theWin, true );
- theWin = (WindowPtr)winList.Next();
- } while( theWin != kODNULL );
- }
-
- return userChangedSize;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleODActivateEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleODActivate( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- ODError result = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
-
- ODFileSpec fileSpec;
- AppleEvent realMessage;
- DescType unused1;
- Size unused2;
- ODBoolean wasPrintEvent = kODFalse;
- ODBoolean notAlreadyOpen = kODFalse;
- boolean quitAfterPrint = kODFalse;
- TempODDraft draftToBringForward = kODNULL;
-
- realMessage.dataHandle = NULL;
- TRY
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyDirectObject, typeFSS,
- &unused1, (Ptr)&fileSpec, sizeof(fileSpec), &unused2));
- DescType spawningEventID;
- OSErr err = AEGetParamPtr(&realMessage, keyODActivateEventCause,
- typeType, &unused1, (Ptr)&spawningEventID,
- sizeof(spawningEventID), &unused2 );
- if ( err == noErr )
- wasPrintEvent = spawningEventID == kAEPrintDocuments;
- // else drop the error: id not present is ok.
-
- err = AEGetParamPtr( &realMessage, keyODRefnumFromResource,
- typeBoolean, &unused1, (Ptr)&quitAfterPrint,
- sizeof(quitAfterPrint), &unused2 );
- if ( err != noErr )
- quitAfterPrint = kODFalse;
-
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- ODDisposeAppleEvent(&realMessage);
-
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
-
- if ( result == noErr )
- {
- ODULong refNumCount, i;
- ODSShort* refNums = kODNULL;
- GetLocalPaths(&fileSpec, kDataFork, &refNumCount, &refNums);
-
- if (refNumCount != 0)
- {
- for ( i=0; i<refNumCount; ++i)
- {
- ODDocument* doc = ODGetOpenDocumentFromRefNum(ev,
- session, refNums[i]);
- if ( doc != kODNULL )
- {
- draftToBringForward = ODGetTempDraftFromOpenDocument( ev,
- session, doc );
-
- if (draftToBringForward)
- draftToBringForward->Acquire(ev); // balance destructor of TempRef
- else
- draftToBringForward =
- doc->AcquireDraft(ev,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
-
- break; // exit for loop
- }
- }
-
- if (refNums)
- DisposePtr((Ptr)refNums);
- }
- else // *if* this process is supposed to handle this event at
- { // all, the ODActivate must have come because of a resource
- // fork.
- short resRefNum = CurResFile();
- if ( refNums != kODNULL )
- {
- DisposePtr( (Ptr)refNums );
- refNums = kODNULL;
- }
- GetLocalPaths( &fileSpec, kResourceFork, &refNumCount, &refNums );
- for ( i=0; i<refNumCount; ++i )
- {
- if ( refNums[i] == resRefNum ) // it belongs in this process
- {
- TempPlatformFile file = new PlatformFile;
- file->Specify( &fileSpec );
- draftToBringForward = ODOpenFileDocument( ev, session, file,
- kODDPSharedWrite );
- WARN("When does this happen?????");
- self->InstallShellPlugIns(draftToBringForward);
- notAlreadyOpen = kODTrue;
- break;
- }
- }
- if( refNums != kODNULL )
- DisposePtr( (Ptr)refNums );
- }
- }
-
- if ( draftToBringForward != kODNULL )
- {
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcess(&psn);
- WARN("ODOpenDraft called.");
- ODOpenDraft( ev, session, draftToBringForward );
- if ( notAlreadyOpen )
- {
- // the plugin may have patched these....
- self->fDispatcher = session->GetDispatcher(ev);
- self->fWindowState = session->GetWindowState(ev);
- }
- if ( wasPrintEvent )
- {
- self->FakePrintMenuEvent();
- if ( quitAfterPrint )
- {
- // need to release draft's refcount *before* calling
- // ODCloseDocument (or check with Tantek to see if
- // assertion in ODCloseDocument can be removed.
- ODDocument* doc = draftToBringForward->GetDocument(ev);
- draftToBringForward->Release(ev);
- draftToBringForward = kODNULL; // prevent another release by the TempRef
- ODBoolean wasLastDoc = ODCloseDocument( ev, session, doc );
- WASSERT( !wasLastDoc );
- }
- }
- }
-
- return result; // usually should be eventNotHandled?
- } // HandleODActivate
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CoerceToFSSpec
- //
- ////////////////////////////////////////////////////////////////////////////////
-
-
- pascal ODError RealShell::CoerceToFSSpec( ODPart* thePart, ODDesc* theAEDesc,
- DescType toType, ODSLong handlerRefCon, ODDesc* result )
- {
- ODUnused(thePart);
- RealShell* self = (RealShell*)handlerRefCon;
-
- if (self->fAlreadyInCoercion)
- return errAECoercionFail;
- else
- self->fAlreadyInCoercion = kODTrue;
- ODError error = noErr;
-
- TRY
- TempAEDescStruct realInDesc;
- THROW_IF_ERROR( ODDescToAEDesc(theAEDesc, &realInDesc));
- if (realInDesc.descriptorType == typeAlias)
- {
- // use the built-in coercion first
- TempAEDescStruct tmpResult;
- error = AECoerceDesc( &realInDesc, toType, &tmpResult );
-
- if ( error == noErr )
- THROW_IF_ERROR( AEDescToODDesc( &tmpResult, result ));
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- self->fAlreadyInCoercion = kODFalse;
- return error;
- } // CoerceToFSSpec()
-
- //----------------------------------------------------------------------------------------
- // RealShell::SetAEError
- //----------------------------------------------------------------------------------------
-
- void RealShell::SetAEError(ODError error)
- {
- fErrorFromOpenEvents = error;
- }
-
- //----------------------------------------------------------------------------------------
- // RealShell::GetAEError
- //----------------------------------------------------------------------------------------
-
- ODError RealShell::GetAEError()
- {
- return fErrorFromOpenEvents;
- }
-
- //==============================================================================
- // Functions
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // HandleGetAETE
- //------------------------------------------------------------------------------
-
-
- pascal ODError HandleGetAETE(ODPart* thePart,
- ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc theAETE = NULL_DESCRIPTOR_DEFINITION;
- DescType returnedType;
- ODSize actualSize;
- ODSLong languageCode;
- ODError result;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- result = AEGetParamPtr(&realMessage, keyDirectObject, typeLongInteger,
- &returnedType, (Ptr)&languageCode, sizeof(languageCode),
- (Size *)&actualSize);
- ODDisposeAppleEvent(&realMessage);
- THROW_IF_ERROR(result);
-
- TRY
- CUsingLibraryResources ref;
-
- theAETE.dataHandle = Get1Resource(typeAETE, (short)languageCode);
- if (theAETE.dataHandle)
- {
- theAETE.descriptorType = typeAETE;
- result = AEPutParamDesc(&realReply, keyAEResult, &theAETE);
- ReleaseResource(theAETE.dataHandle);
- THROW_IF_ERROR(result);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- THROW_IF_ERROR(error);
-
- THROW_IF_ERROR(AEDescToODDesc(&realReply, reply));
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
- AEDisposeDesc(&realReply);
-
- return error;
- } // HandleGetAETE()
-
-
- //------------------------------------------------------------------------------
- // GetFileFromNULL
- //------------------------------------------------------------------------------
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODError error = noErr;
- AEDesc aeAlias, tmp;
- char state;
-
- TRY
- // get the selectionData and coerce it into an fsspec
- THROW_IF_ERROR(ODDescToAEDesc(selectionData, &tmp));
- TempAEDesc tmpDesc(&tmp);
- state = HGetState(tmp.dataHandle);
- HLock(tmp.dataHandle);
- THROW_IF_ERROR(NewAliasMinimalFromFullPath(GetHandleSize(tmp.dataHandle),
- *tmp.dataHandle, "\p", "\p",
- (AliasHandle*)&aeAlias.dataHandle ));
- HSetState(tmp.dataHandle, state);
- aeAlias.descriptorType = typeAlias;
- TempAEDesc tmpDesc2(&aeAlias);
- UpdateUserToken(ev, resolver, value, &aeAlias);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // GetFileFromNULL
-
- //------------------------------------------------------------------------------
- // HandleClone
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleClone( ODPart* thePart, ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT( &realMessage,
- (RealShell*)handlerRefcon );
-
- AEDesc cloneLocation;
- THROW_IF_ERROR( AEGetParamDesc( &realMessage, keyAEInsertHere,
- typeInsertionLoc, &cloneLocation ) );
-
- AEDesc replyDp;
- handlerObj->Clone( &cloneLocation, &replyDp );
- delete handlerObj;
-
- THROW_IF_ERROR( AEPutParamDesc( &realReply, keyDirectObject, &replyDp ) );
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleClone()
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleClose
- //------------------------------------------------------------------------------
-
- pascal ODError HandleClose( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- // can't use TempAEDescs for these because they don't call
- // ODDisposeAppleEvent
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- TempAEDesc tmpDesc(&theFile);
- ThrowIfNotAbsent(err);
-
- DescType saveOptions = kAEAsk, typeFound;
- Size actualSize;
- err = AEGetParamPtr(&realMessage, keyAESaveOptions, typeEnumeration,
- &typeFound, (Ptr)&saveOptions, sizeof(saveOptions), &actualSize);
- ThrowIfNotAbsent(err);
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Close(&theFile, saveOptions);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- }
-
- //------------------------------------------------------------------------------
- // HandleCountEl
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleCountEl(ODPart* thePart, ODAppleEvent* message, ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
-
- DescType elemClass, typeFound;
- Size actualSize;
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&elemClass, sizeof(elemClass), &actualSize));
-
- AEDesc replyDp;
- handlerObj->CountElements(elemClass, &replyDp);
- delete handlerObj;
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMake
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMake(ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
- ODUnused(reply);
-
- DescType newObjClass, typeFound;
- Size actualSize;
- AEDesc insertHere, newObjectName;
- OSErr err;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&newObjClass, sizeof(newObjClass), &actualSize));
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEInsertHere,
- typeInsertionLoc, &insertHere));
- err = AEGetParamDesc(&realMessage, 'type', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- err = AEGetParamDesc(&realMessage, 'subj', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDelete
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDelete( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Delete();
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDoExist
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDoExist( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetClsInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetClsInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc evtDp;
- AEDesc replyDp;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- replyDp.dataHandle = NULL;
- evtDp.dataHandle = NULL;
-
- GetDirectParam((RealShell*)handlerRefcon, &realMessage,
- &evtDp);
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
- // ODDeleteObject(myTokenODDesc);
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->GetPropertyData(&replyDp);
- delete accessorObj;
- break;
-
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
- THROW_IF_ERROR( AEDescToODDesc(&realReply, reply ) );
-
- AEDisposeDesc(&evtDp);
- AEDisposeDesc(&replyDp);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleGetData();
- #endif /* TO_BE_DELETED */
-
-
- //------------------------------------------------------------------------------
- // HandleGetDataSz
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetDataSz( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetEvnInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetEvnInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMove
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMove( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleOpen
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleOpen( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandlePrint
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandlePrint( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleSave
- //------------------------------------------------------------------------------
-
- pascal ODError HandleSave( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- ThrowIfNotAbsent(err);
-
- // keyAEFileType
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Save(&theFile /*,&theFileType*/);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- } // HandleSave()
-
- //------------------------------------------------------------------------------
- // HandleSetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleSetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc dataDesc;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- // THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- dataDesc.dataHandle = NULL;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEData, typeWildCard,
- &dataDesc));
-
- AEDesc evtDp;
- GetDirectParam( self, &realMessage, &evtDp );
- AEDisposeDesc( &realMessage );
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken) );
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->SetPropertyData(&dataDesc);
- delete accessorObj;
- break;
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- AEDisposeDesc(&myToken);
- AEDisposeDesc(&dataDesc);
-
- CATCH_ALL
- AEDisposeDesc(&dataDesc);
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleSetData()
- #endif /* TO_BE_DELETED */
-
-
- //******************************************************************************
- // Utility functions
- //******************************************************************************
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* message,
- RealShell* self)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AEDesc evtDp;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &evtDp));
- TempAEDesc tmpdesc(&evtDp);
-
- ShellEventHandler* handlerObj;
- if (evtDp.descriptorType == typeNull)
- {
- handlerObj = new ShellEventHandler(typeNull, (ODObject*)self,
- (ODSLong)self);
- }
- else
- {
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
-
- handlerObj = FIRSTBYTESFROMHANDLE(myToken.dataHandle,
- ShellEventHandler*);
- AEDisposeDesc(&myToken);
- // ODDeleteObject(tmpWrapper);
- }
-
- // AEDisposeDesc(&evtDp);
- return handlerObj;
- } // GetHandlerFromAEVT()
-
-
- //------------------------------------------------------------------------------
- // GetDirectParam
- //------------------------------------------------------------------------------
-
- // THIS FUNCTION NEEDS A FIXIN' TO USE THE NEW WAY OF DOING DEFAULT ACCESSORS.
-
- void GetDirectParam(RealShell* self, AppleEvent* message,
- AEDesc* evtDp)
- {
- Environment* ev = somGetGlobalEnvironment();
- AEDesc localDP;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &localDP));
-
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
-
- ODBoolean istoken = resolver->IsODToken(ev, tmpWrapper) ;
- // ODDeleteObject(tmpWrapper);
- if ( istoken )
- {
- *evtDp = localDP;
- }
- else
- {
- WARN("RlShlEv.cpp: GetDirectParam. Found a non-token. About to throw.");
- THROW( errAEEventNotHandled );
- }
- } // GetDirectParam()
-
- //•-----------------------------------------------------------------------------
- //•-----------------------------------------------------------------------------
- //• Utility functions for memory size dialog------------------------------------
- //•-----------------------------------------------------------------------------
- //•-----------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------
- // DoDialogSetup
- //------------------------------------------------------------------------------
-
- static void DoDialogSetup( DialogPtr dialog, PlatformFile* docFile)
- {
- Rect buttonRect;
- short itemType;
- Handle itemHandle;
-
- // Hard-coded values. I hope it's OK for the localizers, but probably not.
- // I tried to make Resorcerer use an ictb, but it was hard to get it to
- // work right.
- long scriptSmallFontSize;
- scriptSmallFontSize = GetScriptVariable(smSystemScript,
- smScriptSmallFondSize);
- dialog->txFont = HiWord(scriptSmallFontSize);
- dialog->txSize = LoWord(scriptSmallFontSize);
-
- SetDialogMemorySize(dialog, gSize);
-
- SetPort(dialog);
-
- // Set the new Document Size in Kbytes
- SetNumText(dialog, kCurDocHeapPrefSizeFld, gSize/1024);
- SetNumText(dialog, kNewDocHeapPrefSizeFld, gSize/1024);
-
- // Hide text about closing and reopening document when clicking OK.
- HideDialogItem(dialog, kSaveChangesTxtItem );
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlInactive); // Dim OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
-
- ShowWindow (dialog);
- HiliteWindow( dialog, true );
-
- PlotArrowIcon(dialog, kArrowControl);
-
- InitCursor ();
-
- #ifdef _APPLEGUIDE_READY_
- DialogSetUpAppleGuide( dialog, kDocHeapAppleGuideButton );
- #endif
- }
-
- //------------------------------------------------------------------------------
- // DoDialogHits
- //
- // Returns whether we should keep gRunning.
- //------------------------------------------------------------------------------
-
- static Boolean DoDialogHits(DialogPtr dialog, short itemHit, ODBoolean increaseSize,
- ODBoolean fatalLowMem)
- {
- Boolean shouldKeepRunning = true;
-
- switch (itemHit)
- {
- case kCancelButton :
- // sz = originalSize; // used to have an OK, Cancel interface.
- case kOKButton :
- shouldKeepRunning = false;
- break;
-
- case kArrowBottom :
- case kArrowTop :
- DoMemorySettingHits(dialog, itemHit, increaseSize, fatalLowMem);
- break;
-
- #ifdef _APPLEGUIDE_READY_
- case kDocHeapAppleGuideButton:
- OpenAppleGuide( ODGetIndShort( kODShellGuideSearchIndices,
- kODShellGuideStringIndexSize ) );
- break;
- #endif
-
- default:
- break;
- }
-
- return shouldKeepRunning;
- }
-
- //------------------------------------------------------------------------------
- // SetDialogMemorySize
- //------------------------------------------------------------------------------
-
- static void SetDialogMemorySize (DialogPtr dlog, Size size)
- {
- long kilobytes = size / 1024;
- Str255 text;
- Rect itemRect;
- short itemType;
- Handle itemHandle;
-
- GetDialogItem (dlog, kNewDocHeapPrefSizeFld, &itemType, &itemHandle, &itemRect);
-
- NumToString (kilobytes, text);
- SetDialogItemText (itemHandle, text);
- }
-
- //------------------------------------------------------------------------------
- // MyUserItemProc
- //------------------------------------------------------------------------------
-
- pascal void MyUserItemProc (DialogPtr dlog, short item)
- {
- /*
- Rect itemRect;
- short itemType;
- Handle itemHandle;
-
- GetDialogItem (dlog, item, &itemType, &itemHandle, &itemRect);
-
- switch (item) {
-
- case kArrowControl :
- case kArrowTop :
- case kArrowBottom :
- PlotArrowIcon(dlog, item);
- break;
-
- case kOKButton : // can be done automatically by Dialog Mgr.
- // PenNormal ();
- // PenSize (3, 3);
- // FrameRoundRect (&itemRect, 16, 16);
- break;
- }
- */
- }
-
- //------------------------------------------------------------------------------
- // DoMemorySettingHits
- //------------------------------------------------------------------------------
-
-
- static void DoMemorySettingHits(DialogPtr dialog, short itemHit, ODBoolean increaseSize,
- ODBoolean fatalLowMem)
- {
- // If parameter increaseSize is true, then do not let doc size go under the original
- // doc size. If the parameter is false, then do let go over the original size.
-
- short itemType;
- Handle itemHandle;
- Rect arrowRect;
- Rect buttonRect;
- Point mousePoint;
- long ignore;
- GrafPtr savePort;
- ODULong tempSize = 0;
- ODULong tempSize1 = 0;
-
- switch (itemHit)
- {
- case kArrowBottom :
- GetDialogItem(dialog, kArrowBottom, &itemType,
- &itemHandle, &arrowRect);
- PlotArrowIcon(dialog, itemHit);
- GetPort(&savePort);
- SetPort(dialog);
- do
- {
- GetMouse(&mousePoint);
- if (PtInRect(mousePoint, &arrowRect))
- {
- gSize -= kSizeIncrement;
- // We want to make sure the user doesn't make the size smaller than:
- // A. The minimum size a document could possibly have.
- // B. The original size of the document if we are supposed to increase the size.
- if (gSize < kDocStubMinHeapSize || (increaseSize && (gSize < gOrigDocSize)))
- {
- gSize += kSizeIncrement;
- HideDialogItem(dialog, kSaveChangesTxtItem );
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlInactive); // Dim OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- }
- else
- {
- SetDialogMemorySize (dialog, gSize);
- if( increaseSize && (gSize <= gOrigDocSize) )
- {
- HideDialogItem(dialog, kSaveChangesTxtItem );
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlInactive); // Dim OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- }
- else
- {
- // If the user can make a change
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlActive); // Enable OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- if( !fatalLowMem )
- ShowDialogItem(dialog, kSaveChangesTxtItem );
- }
- }
- Delay(8, &ignore);
- }
- }
- while (StillDown());
- SetPort(savePort);
- PlotArrowIcon(dialog, kArrowControl);
- break;
-
- case kArrowTop :
- GetDialogItem(dialog, kArrowTop, &itemType,
- &itemHandle, &arrowRect);
- PlotArrowIcon(dialog, itemHit);
- GetPort(&savePort);
- SetPort(dialog);
- do
- {
- GetMouse(&mousePoint);
- if (PtInRect(mousePoint, &arrowRect))
- {
- gSize += kSizeIncrement;
- // We want to make sure the user doesn't make the size bigger than:
- // A. The maximum size a document could possibly have.
- // B. The original size of the document if we are supposed to decrease the size.
- if (gSize > kMaximumSize || (!increaseSize && (gSize > gOrigDocSize)))
- {
- gSize -= kSizeIncrement;
- HideDialogItem(dialog, kSaveChangesTxtItem );
- // Disable OK button. How do you do this???
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlInactive); // Dim OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- }
- else
- {
- SetDialogMemorySize (dialog, gSize);
- if( !increaseSize && ( gSize >= gOrigDocSize ) )
- {
- HideDialogItem(dialog, kSaveChangesTxtItem );
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlInactive); // Dim OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- }
- else
- {
- GetDialogItem(dialog, kOKButton, &itemType, &itemHandle, &buttonRect);
- HiliteControl((ControlHandle)itemHandle, kControlActive); // Enable OK button
- ODOutlineDefaultButtonDrawProc(dialog, kOKButton);
- if( !fatalLowMem )
- ShowDialogItem(dialog, kSaveChangesTxtItem );
- }
- }
- Delay(8, &ignore);
- }
- }
- while (StillDown());
- SetPort(savePort);
- PlotArrowIcon(dialog, kArrowControl);
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // PlotArrowIcon
- //------------------------------------------------------------------------------
-
- static void PlotArrowIcon(DialogPtr dlog, short item)
- {
- RgnHandle tempRgn = NewRgn();
- Handle icon;
- Rect arrowRect;
- short itemType;
- Handle itemHandle;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(dlog);
- GetClip(tempRgn);
- GetDialogItem(dlog, kArrowControl, &itemType, &itemHandle, &arrowRect);
- ClipRect (&arrowRect);
- arrowRect.bottom = arrowRect.top + 32;
- arrowRect.right = arrowRect.left + 32;
-
- switch (item)
- {
- case kArrowControl:
- icon = GetResource('ICON', kNormalIconID);
- break;
- case kArrowTop:
- icon = GetResource('ICON', kUpArrowIconID);
- break;
- case kArrowBottom:
- icon = GetResource('ICON', kDownArrowIconID);
- break;
- }
-
- PlotIcon(&arrowRect, icon);
-
- SetClip(tempRgn);
- DisposeRgn(tempRgn);
- SetPort(savePort);
- }
-
- static void ODOutlineDefaultButtonDrawProc(DialogPtr theDialog, short theItem)
- {
- // NOTE: this proc only works on buttons whose DITL ID is 1. theItem
- // is unused, and so it doesn't matter whether the user item to which
- // this proc is assigned (via SetDialogItem) has any geographical
- // relation to the button.
-
- ODUnused(theItem);
- Rect itemRect;
- Handle itemHandle;
- short itemKind;
-
- WindowPtr buttonWindow;
- WindowPtr savePort;
- PenState savePen;
- short buttonOval;
- Boolean isColorPort;
-
- const short kColorPort = 0xC000;
-
- GetDialogItem(theDialog, kOKButton, &itemKind, &itemHandle, &itemRect);
-
- GetPort(&savePort);
- buttonWindow = (**(ControlHandle)itemHandle).contrlOwner;
- SetPort(buttonWindow);
- GetPenState(&savePen);
- PenNormal();
-
- InsetRect(&itemRect, -4, -4);
- FrameRoundRect(&itemRect, 16, 16);
- buttonOval = ((itemRect.bottom - itemRect.top)/2)+2;
-
- isColorPort = ((((CGrafPtr)buttonWindow)->portVersion & kColorPort) == kColorPort);
-
- if ( (**(ControlHandle)itemHandle).contrlHilite == kControlInactive )
- {
- // Button is inactive, so outline with gray
-
- RGBColor fgSaveColor;
- RGBColor fgNewColor;
- RGBColor bgColor;
- Boolean newGray = false;
-
- if ( isColorPort )
- {
- GetBackColor(&bgColor);
- GetForeColor(&fgSaveColor);
- fgNewColor = fgSaveColor;
-
- Rect globalRect = itemRect;
- LocalToGlobal((Point *)&(globalRect.top));
- LocalToGlobal((Point *)&(globalRect.bottom));
- GDHandle targetDevice = GetMaxDevice(&globalRect);
-
- newGray = GetGray(targetDevice, &bgColor, &fgNewColor);
- }
-
- if ( newGray )
- RGBForeColor(&fgNewColor);
- else
- #ifdef THINK_CPLUS
- PenPat(ODQDGlobals.gray);
- #else
- PenPat(&ODQDGlobals.gray);
- #endif
-
- PenSize(3, 3);
- FrameRoundRect(&itemRect, buttonOval, buttonOval);
-
- if ( isColorPort )
- RGBForeColor(&fgSaveColor);
- }
- else
- {
- // Button is active, so outline with black
- #ifdef THINK_CPLUS
- PenPat(ODQDGlobals.black);
- #else
- PenPat(&ODQDGlobals.black);
- #endif
- PenSize(3, 3);
- FrameRoundRect(&itemRect, buttonOval, buttonOval);
- }
-
- SetPenState(&savePen);
- SetPort(savePort);
- }
- //------------------------------------------------------------------------------
- // AttachUserItemProc
- //------------------------------------------------------------------------------
-
- static void AttachUserItemProc (DialogPtr dlog, short item, UserItemUPP proc)
- {
- Rect itemRect;
- short itemType;
- Handle itemHandle;
-
- GetDialogItem (dlog, item, &itemType, &itemHandle, &itemRect);
- SetDialogItem (dlog, item, itemType, (Handle) proc, &itemRect);
- }
-
- //------------------------------------------------------------------------------
- // SetNumText
- //------------------------------------------------------------------------------
-
- ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- Str255 text;
-
- NumToString(numValue, text);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
- SetDialogItemText(itemHandle,text);
-
- }
-
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
-
- // dh - The following functions that start with DH were taken from the Info dialog
- // code. Should this be factored so that we can share this instead of copying it?
-
- ODStatic ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID)
- {
- // returns 0 if the resource is not found
- ODULong size = 0;
- ODPtr sizeRes =
- file->ReadResourcePtr(kSIZERsrcType, resourceID, kODNULL);
- if (sizeRes != kODNULL)
- {
- memcpy(&size, ((char*)sizeRes)+2, sizeof(size)); // Should probably use a constant.
- ODDisposePtr(sizeRes); // No argument here.
- }
- return size / 1024;
- }
-
- ODStatic void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes)
- {
- if (fromFile == kODNULL)
- fromFile = file;
- ODULong sizeOfResource;
- ODPtr sizeRes =
- fromFile->ReadResourcePtr(kSIZERsrcType, fromResID, &sizeOfResource);
-
- if (sizeRes != kODNULL)
- {
- numKBytes *= 1024; // Should probably use a constant.
- memcpy(((char*)sizeRes)+2, &numKBytes, sizeof(numKBytes)); // Should probably use a constant.
-
- file->WriteResourcePtr(kSIZERsrcType, resourceID, sizeRes, sizeOfResource);
- ODDisposePtr(sizeRes);
- }
- }
-
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file)
- {
- // returns 0 if there is no preferred size
- return DHGetPreferredSizeInSIZE(file, 0); // Should probably use a constant.
- }
-
- ODStatic void DHClearDocumentPreferredHeapSize(PlatformFile* file)
- {
- file->DeleteResource(kSIZERsrcType, 0); // Should probably use constants.
- file->DeleteResource(kSIZERsrcType, 1);
- }
-
-
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes)
- {
- DHSetPreferredSizeInSIZE(file, 0, kODNULL, -1, numKBytes); // Should probably use constants.
- DHSetPreferredSizeInSIZE(file, 1, kODNULL, -1, numKBytes);
- }
-
- ODError CStackPtrList::Add( ODPtr theItem )
- {
- ODError returnErr = noErr;
-
- if( numListItems == maxListItems )
- returnErr = kODErrValueOutOfRange;
- else
- {
- data[numListItems] = theItem;
- numListItems++;
- }
-
- return returnErr;
- }
-
- ODPtr CStackPtrList::Next( void )
- {
- if( ( nextPos > maxListItems - 1 ) || ( nextPos > numListItems -1 ) )
- return (ODPtr)kODNULL;
- else
- return data[nextPos++];
- }
-
-
-